<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Boolean Generators (bool_)</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Spirit 2.59">
<link rel="up" href="../numeric.html" title="Numeric Generators">
<link rel="prev" href="real_number.html" title="Real Number Generators (float_, double_, etc.)">
<link rel="next" href="../operator.html" title="Generator Operators">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="real_number.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../operator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="spirit.karma.reference.numeric.boolean"></a><a class="link" href="boolean.html" title="Boolean Generators (bool_)">Boolean Generators
          (<code class="computeroutput"><span class="identifier">bool_</span></code>)</a>
</h5></div></div></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h0"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.description"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.description">Description</a>
          </h6>
<p>
            As you might expect, the <code class="computeroutput"><span class="identifier">bool_generator</span></code>
            can generate output from boolean values. The <code class="computeroutput"><span class="identifier">bool_generator</span></code>
            generator can be used to generate output from ordinary primitive C/C++
            <code class="computeroutput"><span class="keyword">bool</span></code> values or user defined
            boolean types if the type follows certain expression requirements (for
            more information about the requirements, see <a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.additional_requirements">below</a>)).
            The <code class="computeroutput"><span class="identifier">bool_generator</span></code> is
            a template class. Template parameters fine tune its behavior.
          </p>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h1"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.header"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.header">Header</a>
          </h6>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/numeric/bool.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_bool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
          </p>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h2"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.namespace"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.namespace">Namespace</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                    <p>
                      Name
                    </p>
                  </th></tr></thead>
<tbody>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">lit</span> <span class="comment">// alias:
                      boost::spirit::karma::lit</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">bool_</span> <span class="comment">//
                      alias: boost::spirit::karma::bool_</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">true_</span> <span class="comment">//
                      alias: boost::spirit::karma::true_</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">false_</span> <span class="comment">//
                      alias: boost::spirit::karma::false_</span></code>
                    </p>
                  </td></tr>
</tbody>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              <code class="computeroutput"><span class="identifier">lit</span></code> is reused by the
              <a class="link" href="../string.html" title="String Generators">String Generators</a>,
              the <a class="link" href="../char.html" title="Char Generators">Character Generators</a>,
              and the Numeric Generators. In general, a char generator is created
              when you pass in a character, a string generator is created when you
              pass in a string, and a numeric generator is created when you use a
              numeric (boolean) literal.
            </p></td></tr>
</table></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h3"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.synopsis"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span>
    <span class="keyword">typename</span> <span class="identifier">B</span>
  <span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">bool_generator</span><span class="special">;</span>
</pre>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h4"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.template_parameters"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.template_parameters">Template
            parameters</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Parameter
                    </p>
                  </th>
<th>
                    <p>
                      Description
                    </p>
                  </th>
<th>
                    <p>
                      Default
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">B</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      The boolean base type of the boolean generator.
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="keyword">bool</span></code>
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Policies</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      The policies to use while converting the boolean.
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">bool_policies</span><span class="special">&lt;</span><span class="identifier">B</span><span class="special">&gt;</span></code>
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h5"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.model_of"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.model_of">Model
            of</a>
          </h6>
<div class="blockquote"><blockquote class="blockquote"><p>
              <a class="link" href="../generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a>
            </p></blockquote></div>
<div class="variablelist">
<p class="title"><b>Notation</b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="identifier">b</span></code></span></dt>
<dd><p>
                  Boolean literal, or a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy
                  Argument</a> that evaluates to a boolean value of type <code class="computeroutput"><span class="identifier">B</span></code>
                </p></dd>
<dt><span class="term"><code class="computeroutput"><span class="identifier">B</span></code></span></dt>
<dd><p>
                  Type of <code class="computeroutput"><span class="identifier">b</span></code>: any
                  type usable as a boolean, or in case of a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy
                  Argument</a>, its return value
                </p></dd>
</dl>
</div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h6"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.expression_semantics"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.expression_semantics">Expression
            Semantics</a>
          </h6>
<p>
            Semantics of an expression is defined only where it differs from, or
            is not defined in <a class="link" href="../generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a>.
          </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Expression
                    </p>
                  </th>
<th>
                    <p>
                      Semantics
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Generate the boolean literal <code class="computeroutput"><span class="identifier">b</span></code>
                      using the default formatting (<code class="computeroutput"><span class="keyword">false</span></code>
                      is generated as <code class="computeroutput"><span class="string">"false"</span></code>,
                      and <code class="computeroutput"><span class="keyword">true</span></code> is generated
                      as <code class="computeroutput"><span class="string">"true"</span></code>).
                      This generator never fails (unless the underlying output stream
                      reports an error).
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">bool_</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Generate the boolean value provided by a mandatory attribute
                      using the default formatting (<code class="computeroutput"><span class="keyword">false</span></code>
                      is generated as <code class="computeroutput"><span class="string">"false"</span></code>,
                      and <code class="computeroutput"><span class="keyword">true</span></code> is generated
                      as <code class="computeroutput"><span class="string">"true"</span></code>).
                      This generator never fails (unless the underlying output stream
                      reports an error).
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">bool_</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Generate the boolean value provided by the immediate literal
                      value the generator is initialized from using the default formatting
                      (<code class="computeroutput"><span class="keyword">false</span></code> is generated
                      as <code class="computeroutput"><span class="string">"false"</span></code>,
                      and <code class="computeroutput"><span class="keyword">true</span></code> is generated
                      as <code class="computeroutput"><span class="string">"true"</span></code>).
                      If this generator has an associated attribute it succeeds only
                      if the attribute is equal to the immediate literal (unless
                      the underlying output stream reports an error). Otherwise this
                      generator fails and does not generate any output.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">true_</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Generate <code class="computeroutput"><span class="string">"true"</span></code>.
                      If this generator has an associated attribute it succeeds only
                      if the attribute is <code class="computeroutput"><span class="keyword">true</span></code>
                      as well (unless the underlying output stream reports an error).
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">false_</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Generate <code class="computeroutput"><span class="string">"false"</span></code>.
                      If this generator has an associated attribute it succeeds only
                      if the attribute is <code class="computeroutput"><span class="keyword">false</span></code>
                      as well (unless the underlying output stream reports an error).
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
<p>
            All generators listed in the table above (except <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>) are predefined specializations of the
            <code class="computeroutput"><span class="identifier">bool_generator</span><span class="special">&lt;</span><span class="identifier">B</span><span class="special">,</span> <span class="identifier">Policies</span><span class="special">&gt;</span></code>
            basic boolean generator type described below. It is possible to directly
            use this type to create boolean generators using a wide range of formatting
            options.
          </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Expression
                    </p>
                  </th>
<th>
                    <p>
                      Semantics
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_generator</span><span class="special">&lt;</span>
    <span class="identifier">B</span><span class="special">,</span> <span class="identifier">Policies</span>
<span class="special">&gt;()</span></pre>
<p>
                    </p>
                  </td>
<td>
                    <p>
                      Generate the boolean of type <code class="computeroutput"><span class="identifier">B</span></code>
                      provided by a mandatory attribute using the specified <code class="computeroutput"><span class="identifier">Policies</span></code> This generator never
                      fails (unless the underlying output stream reports an error).
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_generator</span><span class="special">&lt;</span>
    <span class="identifier">B</span><span class="special">,</span> <span class="identifier">Policies</span>
<span class="special">&gt;()(</span><span class="identifier">b</span><span class="special">)</span></pre>
<p>
                    </p>
                  </td>
<td>
                    <p>
                      Generate the boolean of type <code class="computeroutput"><span class="identifier">B</span></code>
                      provided by the immediate literal value the generator is initialized
                      from, using the specified <code class="computeroutput"><span class="identifier">Policies</span></code>.
                      If this generator has an associated attribute it succeeds only
                      if the attribute is equal to the immediate literal (unless
                      the underlying output stream reports an error). Otherwise this
                      generator fails and does not generate any output.
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              All boolean generators properly respect the <a class="link" href="../directive/upperlower.html" title="Generator Directives Controlling Case Sensitivity (upper[], lower[])"><code class="computeroutput"><span class="identifier">upper</span></code></a> and <a class="link" href="../directive/upperlower.html" title="Generator Directives Controlling Case Sensitivity (upper[], lower[])"><code class="computeroutput"><span class="identifier">lower</span></code></a> directives.
            </p></td></tr>
</table></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h7"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.additional_requirements"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.additional_requirements">Additional
            Requirements</a>
          </h6>
<p>
            The following lists enumerate the requirements which must be met in order
            to use a certain type <code class="computeroutput"><span class="identifier">B</span></code>
            to instantiate and use a <code class="computeroutput"><span class="identifier">bool_generator</span><span class="special">&lt;</span><span class="identifier">B</span><span class="special">,</span> <span class="identifier">Policies</span><span class="special">&gt;</span></code>.
          </p>
<p>
            The type <code class="computeroutput"><span class="identifier">B</span></code>:
          </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
                must be (safely) convertible to <code class="computeroutput"><span class="keyword">bool</span></code>
              </li></ul></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h8"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.attributes"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.attributes">Attributes</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Expression
                    </p>
                  </th>
<th>
                    <p>
                      Attribute
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">bool_</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">unused</span></code>
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">bool_</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="keyword">bool</span></code>, attribute
                      is mandatory (otherwise compilation will fail)
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">bool_</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="keyword">bool</span></code>, attribute
                      is optional, if it is supplied, the generator compares the
                      attribute with <code class="computeroutput"><span class="identifier">b</span></code>
                      and succeeds only if both are equal, failing otherwise.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_generator</span><span class="special">&lt;</span>
    <span class="identifier">B</span><span class="special">,</span> <span class="identifier">Policies</span>
<span class="special">&gt;()</span></pre>
<p>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">B</span></code>, attribute
                      is mandatory (otherwise compilation will fail)
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_generator</span><span class="special">&lt;</span>
    <span class="identifier">B</span><span class="special">,</span> <span class="identifier">Policies</span>
<span class="special">&gt;()(</span><span class="identifier">b</span><span class="special">)</span></pre>
<p>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">B</span></code>, attribute
                      is optional, if it is supplied, the generator compares the
                      attribute with <code class="computeroutput"><span class="identifier">b</span></code>
                      and succeeds only if both are equal, failing otherwise.
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              In addition to their usual attribute of type <code class="computeroutput"><span class="identifier">B</span></code>
              all listed generators accept an instance of a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">B</span><span class="special">&gt;</span></code> as well. If the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;&gt;</span></code> is initialized (holds a value)
              the generators behave as if their attribute was an instance of <code class="computeroutput"><span class="identifier">B</span></code> and emit the value stored in the
              <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;&gt;</span></code>.
              Otherwise the generators will fail.
            </p></td></tr>
</table></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h9"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.boolean_formatting_policies"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.boolean_formatting_policies">Boolean
            Formatting Policies</a>
          </h6>
<p>
            If special formatting of a boolean is needed, overload the policy class
            <code class="computeroutput"><span class="identifier">bool_policies</span><span class="special">&lt;</span><span class="identifier">B</span><span class="special">&gt;</span></code>
            and use it as a template parameter to the <code class="computeroutput"><span class="identifier">bool_generator</span><span class="special">&lt;&gt;</span></code> boolean generator. For instance:
          </p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">special_bool_policy</span> <span class="special">:</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">bool_policies</span><span class="special">&lt;&gt;</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">CharEncoding</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Tag</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">&gt;</span>
    <span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">generate_false</span><span class="special">(</span><span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">b</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="comment">// we want to spell the names of false as eurt (true backwards)</span>
        <span class="keyword">return</span> <span class="identifier">string_inserter</span><span class="special">&lt;</span><span class="identifier">CharEncoding</span><span class="special">,</span> <span class="identifier">Tag</span><span class="special">&gt;::</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">sink</span><span class="special">,</span> <span class="string">"eurt"</span><span class="special">);</span>
    <span class="special">}</span>
<span class="special">};</span>

<span class="keyword">typedef</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">bool_generator</span><span class="special">&lt;</span><span class="identifier">special_bool_policy</span><span class="special">&gt;</span> <span class="identifier">backwards_bool_type</span><span class="special">;</span>
<span class="identifier">backwards_bool_type</span> <span class="keyword">const</span> <span class="identifier">backwards_bool</span><span class="special">;</span>

<span class="identifier">karma</span><span class="special">::</span><span class="identifier">generate</span><span class="special">(</span><span class="identifier">sink</span><span class="special">,</span> <span class="identifier">backwards_bool</span><span class="special">,</span> <span class="keyword">true</span><span class="special">);</span>    <span class="comment">// will output: true</span>
<span class="identifier">karma</span><span class="special">::</span><span class="identifier">generate</span><span class="special">(</span><span class="identifier">sink</span><span class="special">,</span> <span class="identifier">backwards_bool</span><span class="special">(</span><span class="keyword">false</span><span class="special">));</span>   <span class="comment">// will output: uert</span>
</pre>
<p>
            The template parameter <code class="computeroutput"><span class="identifier">B</span></code>
            should be the type to be formatted using the overloaded policy type.
            At the same time <code class="computeroutput"><span class="identifier">B</span></code> will
            be used as the attribute type of the created real number generator. The
            default for <code class="computeroutput"><span class="identifier">B</span></code> is <code class="computeroutput"><span class="keyword">bool</span></code>.
          </p>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h10"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.boolean_formatting_policy_expression_semantics"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.boolean_formatting_policy_expression_semantics">Boolean
            Formatting Policy Expression Semantics</a>
          </h6>
<p>
            A boolean formatting policy should expose the following:
          </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Expression
                    </p>
                  </th>
<th>
                    <p>
                      Description
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Inserter</span>
  <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">OutputIterator</span>
  <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">call</span> <span class="special">(</span><span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span><span class="special">,</span> <span class="identifier">Num</span> <span class="identifier">n</span>
  <span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<p>
                    </p>
                  </td>
<td>
                    <p>
                      This is the main function used to generate the output for a
                      boolean. It is called by the boolean generator in order to
                      perform the conversion. In theory all of the work can be implemented
                      here, but the easiest way is to use existing functionality
                      provided by the type specified by the template parameter <code class="computeroutput"><span class="identifier">Inserter</span></code>. The default implementation
                      of this functions is:
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Inserter</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">OutputIterator</span>
  <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Policies</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="keyword">bool</span>
<span class="identifier">call</span> <span class="special">(</span><span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span><span class="special">,</span> <span class="identifier">B</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">Policies</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">return</span> <span class="identifier">Inserter</span><span class="special">::</span><span class="identifier">call_n</span><span class="special">(</span><span class="identifier">sink</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">p</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
                      <code class="computeroutput"><span class="identifier">sink</span></code> is the
                      output iterator to use for generation
                    </p>
                    <p>
                      <code class="computeroutput"><span class="identifier">b</span></code> is the boolean
                      to convert
                    </p>
                    <p>
                      <code class="computeroutput"><span class="identifier">p</span></code> is the instance
                      of the policy type used to instantiate this real number generator.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">CharEncoding</span><span class="special">,</span>
    <span class="keyword">typename</span> <span class="identifier">Tag</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">generate_false</span><span class="special">(</span>
    <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span><span class="special">,</span> <span class="identifier">B</span> <span class="identifier">b</span><span class="special">);</span>
</pre>
<p>
                    </p>
                  </td>
<td>
                    <p>
                      This function is called to generate the boolean if it is <code class="computeroutput"><span class="keyword">false</span></code>.
                    </p>
                    <p>
                      <code class="computeroutput"><span class="identifier">sink</span></code> is the
                      output iterator to use for generation
                    </p>
                    <p>
                      <code class="computeroutput"><span class="identifier">b</span></code> is the boolean
                      to convert (the value is <code class="computeroutput"><span class="keyword">false</span></code>).
                    </p>
                    <p>
                      The template parameters <code class="computeroutput"><span class="identifier">CharEncoding</span></code>
                      and <code class="computeroutput"><span class="identifier">Tag</span></code> are
                      either of the type <code class="computeroutput"><span class="identifier">unused_type</span></code>
                      or describe the character class and conversion to be applied
                      to any output possibly influenced by either the <code class="computeroutput"><span class="identifier">lower</span><span class="special">[]</span></code>
                      or <code class="computeroutput"><span class="identifier">upper</span><span class="special">[]</span></code>
                      directives.
                    </p>
                    <p>
                      The return value defines the outcome of the whole generator.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">CharEncoding</span><span class="special">,</span>
    <span class="keyword">typename</span> <span class="identifier">Tag</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">generate_true</span><span class="special">(</span>
    <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span><span class="special">,</span> <span class="identifier">B</span> <span class="identifier">b</span><span class="special">);</span>
</pre>
<p>
                    </p>
                  </td>
<td>
                    <p>
                      This function is called to generate the boolean if it is <code class="computeroutput"><span class="keyword">true</span></code>.
                    </p>
                    <p>
                      <code class="computeroutput"><span class="identifier">sink</span></code> is the
                      output iterator to use for generation
                    </p>
                    <p>
                      <code class="computeroutput"><span class="identifier">b</span></code> is the boolean
                      to convert (the value is <code class="computeroutput"><span class="keyword">true</span></code>).
                    </p>
                    <p>
                      The template parameters <code class="computeroutput"><span class="identifier">CharEncoding</span></code>
                      and <code class="computeroutput"><span class="identifier">Tag</span></code> are
                      either of the type <code class="computeroutput"><span class="identifier">unused_type</span></code>
                      or describe the character class and conversion to be applied
                      to any output possibly influenced by either the <code class="computeroutput"><span class="identifier">lower</span><span class="special">[]</span></code>
                      or <code class="computeroutput"><span class="identifier">upper</span><span class="special">[]</span></code>
                      directives.
                    </p>
                    <p>
                      The return value defines the outcome of the whole generator.
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h11"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.complexity"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.complexity">Complexity</a>
          </h6>
<div class="blockquote"><blockquote class="blockquote"><p>
              O(N), where <code class="computeroutput"><span class="identifier">N</span></code> is the
              number of characters needed to represent the generated boolean.
            </p></blockquote></div>
<h6>
<a name="spirit.karma.reference.numeric.boolean.h12"></a>
            <span class="phrase"><a name="spirit.karma.reference.numeric.boolean.example"></a></span><a class="link" href="boolean.html#spirit.karma.reference.numeric.boolean.example">Example</a>
          </h6>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.karma.reference.basics.examples">Basics Examples</a>
              section.
            </p></td></tr>
</table></div>
<p>
            Some includes:
          </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">support_utree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">core</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="keyword">operator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">std_pair</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">proto</span><span class="special">/</span><span class="identifier">deep_copy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
</pre>
<p>
          </p>
<p>
            Some using declarations:
          </p>
<p>
</p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">bool_</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">lit</span><span class="special">;</span>
</pre>
<p>
          </p>
<p>
            Basic usage of an <code class="computeroutput"><span class="identifier">bool_</span></code>
            generator:
          </p>
<p>
</p>
<pre class="programlisting"><span class="identifier">test_generator</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">lit</span><span class="special">(</span><span class="keyword">true</span><span class="special">));</span>
<span class="identifier">test_generator</span><span class="special">(</span><span class="string">"false"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">(</span><span class="keyword">false</span><span class="special">));</span>
<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">(</span><span class="keyword">true</span><span class="special">),</span> <span class="keyword">true</span><span class="special">);</span>
<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">(</span><span class="keyword">true</span><span class="special">),</span> <span class="keyword">false</span><span class="special">);</span>    <span class="comment">// fails (as true != false)!</span>
<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"false"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">,</span> <span class="keyword">false</span><span class="special">);</span>
</pre>
<p>
          </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="real_number.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../operator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
